package com.itheima.controller;

import com.itheima.entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.JedisPool;

import java.util.UUID;

@RestController
@RequestMapping("extra")
public class ExtraController {

    @Autowired
    private JedisPool jedisPool;

    @RequestMapping("getToken")
    public Result getToken() {
        try {
            String token = UUID.randomUUID().toString();
            jedisPool.getResource().setex(token, 60 * 5, token);
            return new Result(true, "获取到token", token);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "未获取验证码");
        }
    }
}
